﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Permissions;
using System.IO;
using System.Security;

//uncomment only for DeclarativeSecurity to protect assemblies
//[assembly: UIPermission(SecurityAction.RequestMinimum, Unrestricted = true)] //pt debugger
//[assembly: FileIOPermissionAttribute(SecurityAction.RequestOptional, Read = @"C:\")] //iti da tot dreptul pe c
//[assembly: FileIOPermissionAttribute(SecurityAction.RequestRefuse, Read = @"C:\Windows")] //dar nu il lasa din windows
namespace Business.ApplicationSecurity
{
    public class DeclarativeSecurityAssembly
    {
        public static void FileRead_WithoutError()
        {
            try
            {
                StreamReader reader = new StreamReader(new FileStream(@"c:\config.sys", FileMode.Open, FileAccess.Read), Encoding.ASCII);
                Console.WriteLine(reader.ReadToEnd());
            }
            catch (SecurityException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        public static void FileRead_WithError()
        {
            try
            {
                StreamReader reader = new StreamReader(new FileStream(@"c:\Windows\win.ini", FileMode.Open, FileAccess.Read), Encoding.ASCII);
                Console.WriteLine(reader.ReadToEnd());
            }
            catch (SecurityException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
